
//
//  RNOLUpdatePayPasswordView.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/19.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLUpdatePayPasswordView.h"


@interface RNOLUpdatePayPasswordView ()

@property (nonatomic,strong) UIView *phoneBgView;
@property (nonatomic,strong) UILabel *phoneNumberLabel;

@property (nonatomic,strong) UIView * inpuFieldBgView;
@property (nonatomic,strong) UITextField *codeTextField;
@property (nonatomic,strong) UIButton *getCodeButton;

@property (nonatomic,strong) UIButton *nextStepButton;

@end


@implementation RNOLUpdatePayPasswordView

- (UIView *)phoneBgView{
    if (!_phoneBgView) {
        _phoneBgView = [RNOLUnitTool createViewWithBackgroundColor: KWhiteColor];
    }
    return _phoneBgView;
}

- (UILabel *)phoneNumberLabel{
    if (!_phoneNumberLabel) {
        _phoneNumberLabel = [RNOLUnitTool createLabelWithText:@"130****4893" textColor:kTextLightGrayColor fontSize:15];
        _phoneNumberLabel.backgroundColor = KWhiteColor;
    }
    return _phoneNumberLabel;
}

- (UIView *)inpuFieldBgView{
    if (!_inpuFieldBgView) {
        _inpuFieldBgView = [RNOLUnitTool createViewWithBackgroundColor: KWhiteColor];
    }
    return _inpuFieldBgView;
}

- (UITextField *)codeTextField{
    if (!_codeTextField) {
        _codeTextField = [[UITextField alloc] init];
        _codeTextField.font = KFontSize(15);
        _codeTextField.placeholder = @"输入验证码";
        _codeTextField.keyboardType = UIKeyboardTypeNumberPad;
    }
    return _codeTextField;
}

- (UIButton *)getCodeButton{
    if (!_getCodeButton) {
        _getCodeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _getCodeButton.backgroundColor = kAppMainColor;
        [_getCodeButton setTitleColor:KWhiteColor forState:UIControlStateNormal];
        [_getCodeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
        _getCodeButton.titleLabel.font = KFontSize(12);
        [_getCodeButton addTarget:self action:@selector(getCodeAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _getCodeButton;
}

- (UIButton *)nextStepButton{
    if (!_nextStepButton) {
        _nextStepButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_nextStepButton setTitle: @"下一步"  forState:UIControlStateNormal];
        [_nextStepButton setTitle: @"下一步" forState: UIControlStateHighlighted];
        [_nextStepButton setBackgroundColor: kAppMainColor forState: UIControlStateNormal];
        [_nextStepButton addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
     }
    return _nextStepButton;
}


- (void)setup{
    [self addSubview: self.phoneBgView];
    [self.phoneBgView addSubview: self.phoneNumberLabel];
    [self addSubview: self.inpuFieldBgView];
    [self.inpuFieldBgView addSubview: self.codeTextField];
    [self.inpuFieldBgView addSubview: self.getCodeButton];
    [self addSubview: self.nextStepButton];
    
    @weakify(self);
    [self.phoneBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.top.equalTo(@15);
        make.left.right.equalTo(self);
        make.height.equalTo(@50);
    }];
    
    [self.phoneNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.left.equalTo(@15);
        make.right.equalTo(self.phoneBgView).offset(-15);
        make.centerY.equalTo(self.phoneBgView.mas_centerY);
        make.height.equalTo(@30);
    }];
    
    [self.inpuFieldBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.top.equalTo(self.phoneBgView.mas_bottom).offset(10);
        make.left.right.height.equalTo(self.phoneBgView);
    }];
    
    
    [self.codeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.left.equalTo(@15);
        make.centerY.mas_equalTo(self.inpuFieldBgView.mas_centerY);
        make.width.equalTo(self.inpuFieldBgView).multipliedBy(0.6);
        make.height.equalTo(@30);
    }];
    
    [self.getCodeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.right.equalTo(self.inpuFieldBgView).offset(-15);
        make.centerY.equalTo(self.inpuFieldBgView.mas_centerY);
        make.left.equalTo(self.codeTextField.mas_right).offset(5);
        make.height.equalTo(@30);
    }];
    
    
    [self.nextStepButton mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.left.equalTo(@20);
        make.right.equalTo(self).offset(-20);
        make.top.equalTo(self.inpuFieldBgView.mas_bottom).offset(30);
        make.height.equalTo(@44);
    }];
    
    ViewRadius(self.getCodeButton, 5);
    ViewRadius(self.nextStepButton, 7);
}



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kBgColor;
        [self setup];
    }
    return self;
}



#pragma mark- 获取验证码
- (void)getCodeAction:(UIButton *)button{
    !self.getCodeBlock? : self.getCodeBlock(button);
    [button addStartTime:10 title:@"获取验证码" waitTittle:@"秒"];
}

#pragma mark- 下一步
- (void)nextAction{
    !self.nextBlock? : self.nextBlock();
}



@end
